//
//  FontManager.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2019年 张强. All rights reserved.
//

import UIKit
import AutoInch
import DeviceKit

/// HelveticaNeue 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: HelveticaNeueFont
public func HelveticaNeueFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "HelveticaNeue", size: FontManager.adaptiveFontSize(pxSize))!
}

/// PingFangSCMediumFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: PingFangSCMediumFont
public func PingFangSCMediumFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "PingFangSC-Medium", size: FontManager.adaptiveFontSize(pxSize))!
}

/// PingFangSCSemiboldFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: PingFangSCSemiboldFont
public func PingFangSCSemiboldFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "PingFangSC-Semibold", size: FontManager.adaptiveFontSize(pxSize))!
}

/// PingFangSCLightFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: PingFangSCLightFont
public func PingFangSCLightFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "PingFangSC-Light", size: FontManager.adaptiveFontSize(pxSize))!
}

/// AshbyBoldFontFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: AshbyBoldFont
public func AshbyBoldFontFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "Ashby-Bold", size: FontManager.adaptiveFontSize(pxSize))!
}

/// AshbblFontFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: AshbyBoldFont
public func AshbblFontFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "Ashbbl", size: FontManager.adaptiveFontSize(pxSize))!
}

/// AshbblBookFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: AshbyBookFont
public func AshbblBookFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "AshbyBook", size: FontManager.adaptiveFontSize(pxSize))!
}

/// AshbBlackFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: AshbyBlackFont
public func AshbBlackFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "AshbyBlack", size: FontManager.adaptiveFontSize(pxSize))!
}

/// PingFangSCRegularFont 字体语法糖
///
/// - Parameter  pxSize
/// - Returns: PingFangSCRegularFont
public func PingFangSCRegularFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.init(name: "PingFangSC-Regular", size: FontManager.adaptiveFontSize(pxSize))!
}

/// 系统字体语法糖
///
/// - Parameter pxSize: pxSize
/// - Returns: systemFont
public func SystemFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: FontManager.adaptiveFontSize(pxSize))
}

/// 系统加粗字体语法糖
///
/// - Parameter  pxSize
/// - Returns: systemFont
public func BoldSystemFont(_ pxSize: CGFloat) -> UIFont {
    return UIFont.boldSystemFont(ofSize: FontManager.adaptiveFontSize(pxSize))
}


/// 字体管理 自适应字体大小
public class FontManager: NSObject {
    /// 根据 UI设计师 标注字体大小生成适应屏幕的大小的字体大小
    ///
    /// - Parameter pxSize: pxSize
    /// - Returns: adaptive size
    static public func adaptiveFontSize(_ pxSize: CGFloat) -> CGFloat {
//        if(pxSize <= 0) {
//            return 10.0
//        } else {
//            return  pxSize * (72/96) * 1.2 * CGFloat((UIScreen.main.bounds.width/320.0))
//        }
//        if [Device.iPhone5, Device.iPhone6, Device.iPhone4].contains(Device.current) {
//            return pxSize
//        }
        
        switch Device.current {
        case .iPhone4, .iPhone5, .iPhone5s, .iPhone6:
            return pxSize
        case .iPhone7, .iPhoneSE, .iPhone8:
            return pxSize + 0.3
        case .iPhone6Plus, .iPhone6sPlus, .iPhone7Plus, .iPhone8Plus, .iPhoneX:
            return pxSize + 0.6
        default:
            return pxSize + 0.9
        }
    }
    
}
